{% extends 'basepl.html' %}
{% load static %}

{% block head %}
    <title>作业管理</title>
    <style>
        #tjshow{
            width: 1100px;
            height: 570px;
            border: gray solid;
            background-color: ghostwhite;
            position: relative;
            margin: 120px 10% 0 10%;
        }
        #fbbtn{
            left: 160px;
            bottom: 20px;
            position: absolute;
            width: 180px;
        }
        .txt{
            width: 450px;
        }
        #ly>p{
            font-size: 10px;
            color: red;
        }
        #ttp{
            width: 430px;
        }
    .page{
        position: absolute;
        bottom: 10px;
        left: 30px;
    }
    </style>
<script src="{% static '/jquery.min.js' %}"></script>
<script type="text/javascript" src='/static/tiny_mce/tiny_mce.js'></script>
<script type="text/javascript">
    tinyMCE.init({
        forced_root_block:'',
        'mode':'textareas',
        'theme':'advanced',

        'width':495,
        'height':400
    });
</script>
<script >
    document.getElementById('tjshow').style.display='none';

    function  getInputid(id) {

            $.get('/zuoye/ajax_tj?fbtext='+$('#'+id).val(),function (data) {

                var test = document.getElementById('tjshow1');
                test.innerHTML='';
                var table = "<form method = 'post' enctype='multipart/form-data'>{% csrf_token %}<table cellpadding='10' cellspacing='5' border='1px' >";
                for (var i = 0; i < data['len']; i++) {
                    table += "<tr>";
                    snm = 'snum' + i.toString();
                    nme = 'sname' + i.toString();
                    tjtxt = 'tjtext' + i.toString();
                    tjtme = 'tjtime' + i.toString();
                    fpath = 'filepath' + i.toString();
                    pf='pingfen'+i.toString();
                    fnlink = "/download?name=" + data[fpath];
                    var dd=data[fpath];
                    index = dd .lastIndexOf("\/");
                    var str  = dd .substring(index + 1, dd .length);
                    n=i.toString();
                    {#if(data[pf]) {#}
                    {#    inText=data[pf];#}
                    {# }else {#}
                    inText = "<input type='text' name="+ n +" "+"value="+data[pf]+ ">";


                    table += "<td width='80'>" + data[snm] + "</td>" + "<td width='80'>" + data[nme] + "</td>" + "<td width='250' id=" +tjtxt+ ">" + data[tjtxt] + "</td>" + "<td width='150'>" + "<a " +
                        "class=relink" + " href=" + fnlink + ">" + str + "</a></td>" + "<td width='170'>" + data[tjtme] + "</td>"+"<td width='160'>"+inText+"</td>";
                }
                table += "</table><input type='submit' value='提交'/><input type='text' id='problem' name='problem' hidden/></form>";
                if(data['len']){
                    document.getElementById('tjshow').style.display='';
                    test.innerHTML += table;
                }else{
                    document.getElementById('tjshow').style.display='none';
                   alert('暂时没有学生提交作业')
                }
                var top=document.getElementById('problem');
                    top.value=data['fbtext'];
                for(var j=0;j<data['len'];j++){
                    tjt = 'tjtext' + j.toString();
                    show1(tjt);
                }
            })
    }
    function show1(name){
            var box = document.getElementById(name);
            var text = box.innerHTML;
            var newBox = document.createElement("div");
            var btn = document.createElement("a");
            newBox.innerHTML = text.substring(0,15);
            btn.innerHTML = text.length > 15 ? "...显示全部" : "";
            btn.href = "###";
            btn.style.fontSize='12px';
            btn.style.fontFamily='宋体';
            btn.style.color='grey';
            btn.onclick = function(){
                if (btn.innerHTML == "...显示全部"){
                    btn.innerHTML = "收起";
                    newBox.innerHTML = text;
                }else{
                    btn.innerHTML = "...显示全部";
                    newBox.innerHTML = text.substring(0,15);
                }
            };
            box.innerHTML = "";
            box.appendChild(newBox);
            box.appendChild(btn);
    }
</script>
{% endblock head %}
{% block nav %}
 <li><a href="/teaIndex">首页</a></li>
<li><a href="#top">大学课程教学过程管理系统</a></li>
<li><a href="/">切换账号</a></li>
<li><a href="#">&#9658;{{ request.session.cname }}&#9668;</a></li>
<li><a href="#">关于</a></li>
<li><a href="/">注销</a></li>
{% endblock nav %}
{% block li %}
<li><a href="/teaIndex/teaTask/cdetail">编&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;辑</a></li>
<li><a href="/teaIndex/teaTask/zuoye">作&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;业</a></li>
<li><a href="/teaIndex/teaTask/chengji">成&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;绩</a></li>
<li><a href="/teaIndex/teaTask/detail?val=mingdan">花&nbsp;名&nbsp;册</a></li>
<li><a href="/teaIndex/teaTask/detail?val=chengjidan">成&nbsp;绩&nbsp;
    单</a></li>
{% endblock li %}

{% block section %}
<div id="ly">
<h3 align="center">发布作业</h3>
    <form id="fb" method = 'post' enctype="multipart/form-data" >
        {% csrf_token %}
        <label>问题：</label><input id="ttp" type="text" name="zy_topic" placeholder="必填" required>&#9889;
        &#9889;<br>
        <label>详细：</label><br>
        <textarea name="zy_text" cols="60" rows="6"></textarea>
        <input id="fbbtn" type="submit" value = "发布" />
    </form>
</div>
<div id="gonggao">
<h3 align="center">历史发布</h3>
  {% if fb_text %}
  <table id="show" cellpadding="2"  >
    {% for i in p %}
    <tr>
        <td>{{ forloop.counter }}</td>
        <td ><input class="txt" width="300px" type="button" id="input{{ i.zyid }}" value="{{ i.zytopic }}" onclick="getInputid(id)"/></td>
    </tr>
    {% endfor %}
  </table>
      <div class="page">
        {% if p.has_previous %}
            <a href="/teaIndex/teaTask/zuoye/{{ p.previous_page_number}}">上一页</a>
        {% endif %}
            {% for foo in pg.page_range %}
                {% if foo == p.number %}
                    <a href="#">{{ foo }}</a>
                    {% else %}
                    <a href="/teaIndex/teaTask/zuoye/{{ foo }}"
                    >{{ foo }}</a>
                {% endif %}
            {% endfor %}
        {% if p.has_next %}
            <a href="/teaIndex/teaTask/zuoye/{{ p.next_page_number }}">下一页</a>
        {% endif %}
      </div>
  {% else %}
    <span>未发布过作业</span>
  {% endif %}

</div>
{% endblock section %}

{% block tjshow %}
<div id="tjshow" >
    <table cellpadding="10" cellspacing="5"  border="1px" id="t1">
        <tr>
            <td width="80" >学号</td>
            <td width="80">姓名</td>
            <td  width="250">提交内容</td>
            <td width="150">文件路径</td>
            <td width="170">提交时间</td>
            <td width="160">评分</td>
        </tr>
    </table>
    <div id="tjshow1">

    </div>
</div>
{% endblock tjshow%}

